package dynamic.metadata;

import com.baomidou.mybatisplus.annotation.IdType;

import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import dynamic.DynamicEntity;
import dynamic.ibatis.mapping.DResultMap;
import dynamic.ibatis.mapping.DResultMapping;
import dynamic.ibatis.session.DConfiguration;
import dynamic.metadata.property.KeySequence;
import org.apache.ibatis.mapping.ResultFlag;
import org.apache.ibatis.mapping.ResultMap;
import org.apache.ibatis.mapping.ResultMapping;
import org.apache.ibatis.session.Configuration;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class DTableInfo implements Constants {
        private EntityClass entityType;
        private IdType idType;
        private String tableName;
        private String resultMap;
        private boolean autoInitResultMap;
        private boolean keyRelated;
        private String keyColumn;
        private String keyProperty;
        private Class<?> keyType;
        private KeySequence keySequence;
        private List<DTableFieldInfo> fieldList;
        private String currentNamespace;
        /** @deprecated */
        @Deprecated
        private DConfiguration configuration;
        private boolean underCamel;
        private String allSqlSelect;
        private String sqlSelect;
        private boolean withInsertFill;
        private boolean withUpdateFill;
        private boolean withLogicDelete;
        private DTableFieldInfo logicDeleteFieldInfo;
        private boolean withVersion;
        private DTableFieldInfo versionFieldInfo;
        private List<DOrderFieldInfo> orderByFields;
        public DTableInfo(DConfiguration configuration, EntityClass entityType) {
            this.idType = IdType.NONE;
            this.configuration = configuration;
            this.entityType = entityType;

            this.underCamel = configuration.isMapUnderscoreToCamelCase();
        }

        /** @deprecated */
        @Deprecated
        public String getSqlStatement(String sqlMethod) {
            return this.currentNamespace + "." + sqlMethod;
        }

        public boolean havePK() {
            return StringUtils.isNotBlank(this.keyColumn);
        }

        public String getKeySqlSelect() {
            if (this.sqlSelect == null) {
                if (this.havePK()) {
                    this.sqlSelect = this.keyColumn;
                    if (this.resultMap == null && this.keyRelated) {
                        this.sqlSelect = this.sqlSelect + " AS " + this.keyProperty;
                    }
                } else {
                    this.sqlSelect = "";
                }

            }
            return this.sqlSelect;
        }

        public String getAllSqlSelect() {
            if (this.allSqlSelect != null) {
                return this.allSqlSelect;
            } else {
                this.allSqlSelect = this.chooseSelect(DTableFieldInfo::isSelect);
                return this.allSqlSelect;
            }
        }

        public String chooseSelect(Predicate<DTableFieldInfo> predicate) {
            String sqlSelect = this.getKeySqlSelect();
            String fieldsSqlSelect = (String)this.fieldList.stream().filter(predicate).map(DTableFieldInfo::getSqlSelect).collect(Collectors.joining(","));
            if (StringUtils.isNotBlank(sqlSelect) && StringUtils.isNotBlank(fieldsSqlSelect)) {
                return sqlSelect + "," + fieldsSqlSelect;
            } else {
                return StringUtils.isNotBlank(fieldsSqlSelect) ? fieldsSqlSelect : sqlSelect;
            }
        }

        public String getKeyInsertSqlProperty(final boolean batch, final String prefix, final boolean newLine) {
            String newPrefix = prefix == null ? "" : prefix;
            if (this.havePK()) {
                String prefixKeyProperty = newPrefix + this.keyProperty;
                String keyColumn = SqlScriptUtils.safeParam(prefixKeyProperty) + ",";
                if (this.idType == IdType.AUTO) {
                    return batch ? "" : SqlScriptUtils.convertIf(keyColumn, String.format("%s != null", prefixKeyProperty), newLine);
                } else {
                    return keyColumn + (newLine ? "\n" : "");
                }
            } else {
                return "";
            }
        }

        public String getKeyInsertSqlColumn(final boolean batch, final String prefix, final boolean newLine) {
            if (this.havePK()) {
                String newPrefix = prefix == null ? "" : prefix;
                String prefixKeyProperty = newPrefix + this.keyProperty;
                if (this.idType == IdType.AUTO) {
                    return batch ? "" : SqlScriptUtils.convertIf(this.keyColumn + ",", String.format("%s != null", prefixKeyProperty), newLine);
                } else {
                    return this.keyColumn + "," + (newLine ? "\n" : "");
                }
            } else {
                return "";
            }
        }

        public String getAllInsertSqlPropertyMaybeIf(final String prefix) {
            return this.getAllInsertSqlPropertyMaybeIf(prefix, false);
        }

        public String getAllInsertSqlPropertyMaybeIf(final String prefix, boolean ignoreAutoIncrementColumn) {
            String newPrefix = prefix == null ? "" : prefix;
            return ignoreAutoIncrementColumn ? (String)this.fieldList.stream().map((i) -> {
                return i.getInsertSqlPropertyMaybeIf(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n")) : this.getKeyInsertSqlProperty(false, newPrefix, true) + (String)this.fieldList.stream().map((i) -> {
                return i.getInsertSqlPropertyMaybeIf(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n"));
        }

        public String getAllInsertSqlColumnMaybeIf(final String prefix) {
            return this.getAllInsertSqlColumnMaybeIf(prefix, false);
        }

        public String getAllInsertSqlColumnMaybeIf(final String prefix, boolean ignoreAutoIncrementColumn) {
            String newPrefix = prefix == null ? "" : prefix;
            return ignoreAutoIncrementColumn ? (String)this.fieldList.stream().map((i) -> {
                return i.getInsertSqlColumnMaybeIf(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n")) : this.getKeyInsertSqlColumn(false, newPrefix, true) + (String)this.fieldList.stream().map((i) -> {
                return i.getInsertSqlColumnMaybeIf(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n"));
        }

        public String getAllSqlWhere(boolean fistAnd, boolean ignoreLogicDelFiled, boolean withId, final String prefix) {
            String newPrefix = prefix == null ? "" : prefix;
            String filedSqlScript = (String)this.fieldList.stream().filter((i) -> {
                if (!ignoreLogicDelFiled) {
                    return true;
                } else {
                    return !this.isWithLogicDelete() || !i.isLogicDelete();
                }
            }).map((i) -> {
                return i.getSqlWhere(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n"));
            if (withId && !StringUtils.isBlank(this.keyProperty)) {
                String newKeyProperty = newPrefix + this.keyProperty;
                String keySqlScript = this.keyColumn + "=" + SqlScriptUtils.safeParam(newKeyProperty);
                return SqlScriptUtils.convertIf(fistAnd ? " AND " + keySqlScript : keySqlScript, String.format("%s != null", newKeyProperty), false) + "\n" + filedSqlScript;
            } else {
                return filedSqlScript;
            }
        }

        public String getAllSqlSet(boolean ignoreLogicDelFiled, final String prefix) {
            String newPrefix = prefix == null ? "" : prefix;
            return (String)this.fieldList.stream().filter((i) -> {
                if (!ignoreLogicDelFiled) {
                    return true;
                } else {
                    return !this.isWithLogicDelete() || !i.isLogicDelete();
                }
            }).map((i) -> {
                return i.getSqlSet(newPrefix);
            }).filter(Objects::nonNull).collect(Collectors.joining("\n"));
        }

        public String getLogicDeleteSql(boolean startWithAnd, boolean isWhere) {
            if (this.withLogicDelete) {
                String logicDeleteSql = this.formatLogicDeleteSql(isWhere);
                if (startWithAnd) {
                    logicDeleteSql = " AND " + logicDeleteSql;
                }

                return logicDeleteSql;
            } else {
                return "";
            }
        }

        protected String formatLogicDeleteSql(boolean isWhere) {
            String value = isWhere ? this.logicDeleteFieldInfo.getLogicNotDeleteValue() : this.logicDeleteFieldInfo.getLogicDeleteValue();
            if (isWhere) {
                return "null".equalsIgnoreCase(value) ? this.logicDeleteFieldInfo.getColumn() + " IS NULL" : this.logicDeleteFieldInfo.getColumn() + "=" + String.format(this.logicDeleteFieldInfo.isCharSequence() ? "'%s'" : "%s", value);
            } else {
                String targetStr = this.logicDeleteFieldInfo.getColumn() + "=";
                return "null".equalsIgnoreCase(value) ? targetStr + "null" : targetStr + String.format(this.logicDeleteFieldInfo.isCharSequence() ? "'%s'" : "%s", value);
            }
        }

       public void initResultMapIfNeed() {
            if (this.autoInitResultMap && null == this.resultMap) {
                String id = this.currentNamespace + "." + "mybatis-plus" + "_" + this.entityType.getSimpleName();
                List<DResultMapping> resultMappings = new ArrayList();
                if (this.havePK()) {
                    DResultMapping idMapping = (new DResultMapping.Builder(this.configuration, this.keyProperty, StringUtils.getTargetColumn(this.keyColumn), this.keyType)).flags(Collections.singletonList(ResultFlag.ID)).build();
                    resultMappings.add(idMapping);
                }

                if (CollectionUtils.isNotEmpty(this.fieldList)) {
                    this.fieldList.forEach((i) -> {
                        resultMappings.add(i.getResultMapping(this.configuration));
                    });
                }

                DResultMap resultMap = (new DResultMap.Builder(this.configuration, id, Map.class, resultMappings)).build();
                this.configuration.addResultMap(resultMap);
                this.resultMap = id;
            }

        }

        void setFieldList(List<DTableFieldInfo> fieldList) {
            this.fieldList = fieldList;
            AtomicInteger logicDeleted = new AtomicInteger();
            AtomicInteger version = new AtomicInteger();
            fieldList.forEach((i) -> {
                if (i.isLogicDelete()) {
                    this.withLogicDelete = true;
                    this.logicDeleteFieldInfo = i;
                    logicDeleted.getAndAdd(1);
                }

                if (i.isWithInsertFill()) {
                    this.withInsertFill = true;
                }

                if (i.isWithUpdateFill()) {
                    this.withUpdateFill = true;
                }

                if (i.isVersion()) {
                    this.withVersion = true;
                    this.versionFieldInfo = i;
                    version.getAndAdd(1);
                }

            });
            Assert.isTrue(logicDeleted.get() <= 1, "@TableLogic not support more than one in Class: \"%s\"", new Object[]{this.entityType.getName()});
            Assert.isTrue(version.get() <= 1, "@Version not support more than one in Class: \"%s\"", new Object[]{this.entityType.getName()});
        }

        public List<DTableFieldInfo> getFieldList() {
            return Collections.unmodifiableList(this.fieldList);
        }

        public List<DOrderFieldInfo> getOrderByFields() {
            if (null == this.orderByFields) {
                this.orderByFields = new LinkedList();
            }

            return this.orderByFields;
        }

        /** @deprecated */
        @Deprecated
        public boolean isLogicDelete() {
            return this.withLogicDelete;
        }

        public Object getPropertyValue(DynamicEntity entity, String property) {
            try {
                return entity.get(property);
            } catch (Exception var4) {
                throw ExceptionUtils.mpe("Error: Cannot read property in %s.  Cause:", var4, new Object[]{entity.getClass().getSimpleName()});
            }
        }

        public void setPropertyValue(DynamicEntity entity, String property, Object... values) {
            try {
                entity.put(property,values[0]);
            } catch (Exception var5) {
                throw ExceptionUtils.mpe("Error: Cannot write property in %s.  Cause:", var5, new Object[]{entity.getClass().getSimpleName()});
            }
        }

        public Map  newInstance() {
            return new HashMap();
        }

        public EntityClass getEntityType() {
            return this.entityType;
        }

        public IdType getIdType() {
            return this.idType;
        }

        public String getTableName() {
            return this.tableName;
        }

        public String getResultMap() {
            return this.resultMap;
        }

        public boolean isAutoInitResultMap() {
            return this.autoInitResultMap;
        }

        public boolean isKeyRelated() {
            return this.keyRelated;
        }

        public String getKeyColumn() {
            return this.keyColumn;
        }

        public String getKeyProperty() {
            return this.keyProperty;
        }

        public Class<?> getKeyType() {
            return this.keyType;
        }

        public KeySequence getKeySequence() {
            return this.keySequence;
        }

        public String getCurrentNamespace() {
            return this.currentNamespace;
        }

        public boolean isUnderCamel() {
            return this.underCamel;
        }

        public boolean equals(final Object o) {
            if (o == this) {
                return true;
            } else if (!(o instanceof DTableInfo)) {
                return false;
            } else {
                DTableInfo other = (DTableInfo)o;
                if (!other.canEqual(this)) {
                    return false;
                } else if (this.isAutoInitResultMap() != other.isAutoInitResultMap()) {
                    return false;
                } else if (this.isKeyRelated() != other.isKeyRelated()) {
                    return false;
                } else if (this.isUnderCamel() != other.isUnderCamel()) {
                    return false;
                } else if (this.isWithInsertFill() != other.isWithInsertFill()) {
                    return false;
                } else if (this.isWithUpdateFill() != other.isWithUpdateFill()) {
                    return false;
                } else if (this.isWithLogicDelete() != other.isWithLogicDelete()) {
                    return false;
                } else if (this.isWithVersion() != other.isWithVersion()) {
                    return false;
                } else {
                    label232: {
                        Object this$entityType = this.getEntityType();
                        Object other$entityType = other.getEntityType();
                        if (this$entityType == null) {
                            if (other$entityType == null) {
                                break label232;
                            }
                        } else if (this$entityType.equals(other$entityType)) {
                            break label232;
                        }

                        return false;
                    }

                    label225: {
                        Object this$idType = this.getIdType();
                        Object other$idType = other.getIdType();
                        if (this$idType == null) {
                            if (other$idType == null) {
                                break label225;
                            }
                        } else if (this$idType.equals(other$idType)) {
                            break label225;
                        }

                        return false;
                    }

                    Object this$tableName = this.getTableName();
                    Object other$tableName = other.getTableName();
                    if (this$tableName == null) {
                        if (other$tableName != null) {
                            return false;
                        }
                    } else if (!this$tableName.equals(other$tableName)) {
                        return false;
                    }

                    Object this$resultMap = this.getResultMap();
                    Object other$resultMap = other.getResultMap();
                    if (this$resultMap == null) {
                        if (other$resultMap != null) {
                            return false;
                        }
                    } else if (!this$resultMap.equals(other$resultMap)) {
                        return false;
                    }

                    label204: {
                        Object this$keyColumn = this.getKeyColumn();
                        Object other$keyColumn = other.getKeyColumn();
                        if (this$keyColumn == null) {
                            if (other$keyColumn == null) {
                                break label204;
                            }
                        } else if (this$keyColumn.equals(other$keyColumn)) {
                            break label204;
                        }

                        return false;
                    }

                    Object this$keyProperty = this.getKeyProperty();
                    Object other$keyProperty = other.getKeyProperty();
                    if (this$keyProperty == null) {
                        if (other$keyProperty != null) {
                            return false;
                        }
                    } else if (!this$keyProperty.equals(other$keyProperty)) {
                        return false;
                    }

                    Object this$keyType = this.getKeyType();
                    Object other$keyType = other.getKeyType();
                    if (this$keyType == null) {
                        if (other$keyType != null) {
                            return false;
                        }
                    } else if (!this$keyType.equals(other$keyType)) {
                        return false;
                    }

                    label183: {
                        Object this$keySequence = this.getKeySequence();
                        Object other$keySequence = other.getKeySequence();
                        if (this$keySequence == null) {
                            if (other$keySequence == null) {
                                break label183;
                            }
                        } else if (this$keySequence.equals(other$keySequence)) {
                            break label183;
                        }

                        return false;
                    }

                    Object this$fieldList = this.getFieldList();
                    Object other$fieldList = other.getFieldList();
                    if (this$fieldList == null) {
                        if (other$fieldList != null) {
                            return false;
                        }
                    } else if (!this$fieldList.equals(other$fieldList)) {
                        return false;
                    }

                    label169: {
                        Object this$currentNamespace = this.getCurrentNamespace();
                        Object other$currentNamespace = other.getCurrentNamespace();
                        if (this$currentNamespace == null) {
                            if (other$currentNamespace == null) {
                                break label169;
                            }
                        } else if (this$currentNamespace.equals(other$currentNamespace)) {
                            break label169;
                        }

                        return false;
                    }

                    Object this$configuration = this.getConfiguration();
                    Object other$configuration = other.getConfiguration();
                    if (this$configuration == null) {
                        if (other$configuration != null) {
                            return false;
                        }
                    } else if (!this$configuration.equals(other$configuration)) {
                        return false;
                    }

                    Object this$allSqlSelect = this.getAllSqlSelect();
                    Object other$allSqlSelect = other.getAllSqlSelect();
                    if (this$allSqlSelect == null) {
                        if (other$allSqlSelect != null) {
                            return false;
                        }
                    } else if (!this$allSqlSelect.equals(other$allSqlSelect)) {
                        return false;
                    }

                    Object this$sqlSelect = this.sqlSelect;
                    Object other$sqlSelect = other.sqlSelect;
                    if (this$sqlSelect == null) {
                        if (other$sqlSelect != null) {
                            return false;
                        }
                    } else if (!this$sqlSelect.equals(other$sqlSelect)) {
                        return false;
                    }

                    label141: {
                        Object this$logicDeleteFieldInfo = this.getLogicDeleteFieldInfo();
                        Object other$logicDeleteFieldInfo = other.getLogicDeleteFieldInfo();
                        if (this$logicDeleteFieldInfo == null) {
                            if (other$logicDeleteFieldInfo == null) {
                                break label141;
                            }
                        } else if (this$logicDeleteFieldInfo.equals(other$logicDeleteFieldInfo)) {
                            break label141;
                        }

                        return false;
                    }

                    label134: {
                        Object this$versionFieldInfo = this.getVersionFieldInfo();
                        Object other$versionFieldInfo = other.getVersionFieldInfo();
                        if (this$versionFieldInfo == null) {
                            if (other$versionFieldInfo == null) {
                                break label134;
                            }
                        } else if (this$versionFieldInfo.equals(other$versionFieldInfo)) {
                            break label134;
                        }

                        return false;
                    }

                    Object this$orderByFields = this.getOrderByFields();
                    Object other$orderByFields = other.getOrderByFields();
                    if (this$orderByFields == null) {
                        if (other$orderByFields != null) {
                            return false;
                        }
                    } else if (!this$orderByFields.equals(other$orderByFields)) {
                        return false;
                    }
                    return true;
                }
            }
        }

        protected boolean canEqual(final Object other) {
            return other instanceof DTableInfo;
        }

        public int hashCode() {
            boolean PRIME = true;
            int result = 1;
            result = result * 59 + (this.isAutoInitResultMap() ? 79 : 97);
            result = result * 59 + (this.isKeyRelated() ? 79 : 97);
            result = result * 59 + (this.isUnderCamel() ? 79 : 97);
            result = result * 59 + (this.isWithInsertFill() ? 79 : 97);
            result = result * 59 + (this.isWithUpdateFill() ? 79 : 97);
            result = result * 59 + (this.isWithLogicDelete() ? 79 : 97);
            result = result * 59 + (this.isWithVersion() ? 79 : 97);
            Object $entityType = this.getEntityType();
            result = result * 59 + ($entityType == null ? 43 : $entityType.hashCode());
            Object $idType = this.getIdType();
            result = result * 59 + ($idType == null ? 43 : $idType.hashCode());
            Object $tableName = this.getTableName();
            result = result * 59 + ($tableName == null ? 43 : $tableName.hashCode());
            Object $resultMap = this.getResultMap();
            result = result * 59 + ($resultMap == null ? 43 : $resultMap.hashCode());
            Object $keyColumn = this.getKeyColumn();
            result = result * 59 + ($keyColumn == null ? 43 : $keyColumn.hashCode());
            Object $keyProperty = this.getKeyProperty();
            result = result * 59 + ($keyProperty == null ? 43 : $keyProperty.hashCode());
            Object $keyType = this.getKeyType();
            result = result * 59 + ($keyType == null ? 43 : $keyType.hashCode());
            Object $keySequence = this.getKeySequence();
            result = result * 59 + ($keySequence == null ? 43 : $keySequence.hashCode());
            Object $fieldList = this.getFieldList();
            result = result * 59 + ($fieldList == null ? 43 : $fieldList.hashCode());
            Object $currentNamespace = this.getCurrentNamespace();
            result = result * 59 + ($currentNamespace == null ? 43 : $currentNamespace.hashCode());
            Object $configuration = this.getConfiguration();
            result = result * 59 + ($configuration == null ? 43 : $configuration.hashCode());
            Object $allSqlSelect = this.getAllSqlSelect();
            result = result * 59 + ($allSqlSelect == null ? 43 : $allSqlSelect.hashCode());
            Object $sqlSelect = this.sqlSelect;
            result = result * 59 + ($sqlSelect == null ? 43 : $sqlSelect.hashCode());
            Object $logicDeleteFieldInfo = this.getLogicDeleteFieldInfo();
            result = result * 59 + ($logicDeleteFieldInfo == null ? 43 : $logicDeleteFieldInfo.hashCode());
            Object $versionFieldInfo = this.getVersionFieldInfo();
            result = result * 59 + ($versionFieldInfo == null ? 43 : $versionFieldInfo.hashCode());
            Object $orderByFields = this.getOrderByFields();
            result = result * 59 + ($orderByFields == null ? 43 : $orderByFields.hashCode());
            return result;
        }

        public String toString() {
            return "TableInfo(entityType=" + this.getEntityType() + ", idType=" + this.getIdType() + ", tableName=" + this.getTableName() + ", resultMap=" + this.getResultMap() + ", autoInitResultMap=" + this.isAutoInitResultMap() + ", keyRelated=" + this.isKeyRelated() + ", keyColumn=" + this.getKeyColumn() + ", keyProperty=" + this.getKeyProperty() + ", keyType=" + this.getKeyType() + ", keySequence=" + this.getKeySequence() + ", fieldList=" + this.getFieldList() + ", currentNamespace=" + this.getCurrentNamespace() + ", configuration=" + this.getConfiguration() + ", underCamel=" + this.isUnderCamel() + ", allSqlSelect=" + this.getAllSqlSelect() + ", sqlSelect=" + this.sqlSelect + ", withInsertFill=" + this.isWithInsertFill() + ", withUpdateFill=" + this.isWithUpdateFill() + ", withLogicDelete=" + this.isWithLogicDelete() + ", logicDeleteFieldInfo=" + this.getLogicDeleteFieldInfo() + ", withVersion=" + this.isWithVersion() + ", versionFieldInfo=" + this.getVersionFieldInfo() + ", orderByFields=" + this.getOrderByFields() +  ")";
        }

        DTableInfo setEntityType(EntityClass entityType) {
            this.entityType = entityType;
            return this;
        }

        DTableInfo setIdType(final IdType idType) {
            this.idType = idType;
            return this;
        }

        DTableInfo setTableName(final String tableName) {
            this.tableName = tableName;
            return this;
        }

        DTableInfo setResultMap(final String resultMap) {
            this.resultMap = resultMap;
            return this;
        }

        DTableInfo setAutoInitResultMap(final boolean autoInitResultMap) {
            this.autoInitResultMap = autoInitResultMap;
            return this;
        }

        DTableInfo setKeyRelated(final boolean keyRelated) {
            this.keyRelated = keyRelated;
            return this;
        }

        DTableInfo setKeyColumn(final String keyColumn) {
            this.keyColumn = keyColumn;
            return this;
        }

        DTableInfo setKeyProperty(final String keyProperty) {
            this.keyProperty = keyProperty;
            return this;
        }

        DTableInfo setKeyType(final Class<?> keyType) {
            this.keyType = keyType;
            return this;
        }

        DTableInfo setKeySequence(final KeySequence keySequence) {
            this.keySequence = keySequence;
            return this;
        }

        DTableInfo   setCurrentNamespace(final String currentNamespace) {
            this.currentNamespace = currentNamespace;
            return this;
        }

        DTableInfo setUnderCamel(final boolean underCamel) {
            this.underCamel = underCamel;
            return this;
        }


        /** @deprecated */
        @Deprecated
        public DConfiguration getConfiguration() {
            return this.configuration;
        }

        public boolean isWithInsertFill() {
            return this.withInsertFill;
        }

        public boolean isWithUpdateFill() {
            return this.withUpdateFill;
        }

        public boolean isWithLogicDelete() {
            return this.withLogicDelete;
        }

        public DTableFieldInfo getLogicDeleteFieldInfo() {
            return this.logicDeleteFieldInfo;
        }

        public boolean isWithVersion() {
            return this.withVersion;
        }

        public DTableFieldInfo getVersionFieldInfo() {
            return this.versionFieldInfo;
        }

        public DTableInfo setOrderByFields(final List<DOrderFieldInfo> orderByFields) {
            this.orderByFields = orderByFields;
            return this;
        }


    }
